package com.zzu.chat.chat;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zzu.chat.R;

import cn.leancloud.AVObject;
import cn.leancloud.AVUser;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;


public class UploadActivity extends AppCompatActivity {
    private TextView content;
    private  TextView topic;
    private Button upload;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload);

        content = findViewById(R.id.et_upload);
        topic = findViewById(R.id.et_tag);
        upload = findViewById(R.id.btn_upload);

        upload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String content2=content.getText().toString();
                String topic2 = topic.getText().toString();

                uploadBlinkContent(content2,topic2);

            }
        });
    }

    /**
     * 上传
     */

    private void uploadBlinkContent(String content, String topic) {
        AVUser user = AVUser.getCurrentUser();
        user.getUsername();

        AVObject object = new AVObject("Blink");

        object.put("content", content);
        object.put("username", user.getUsername());

        if (topic != null) {
            object.put("topic", topic);
        }
        object.put("user", user);

        object.saveInBackground().subscribe(new Observer<AVObject>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AVObject avObject) {
                System.out.println("1215"+avObject.getString("content"));
                System.out.println(avObject.getString("topic"));
                UploadActivity.this.finish();
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });


    }
}